home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / init.d / kbd < prev    next >
Encoding:
Text File  |  2010-10-13  |  7.6 KB  |  260 lines

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          kbd
  4. # Required-Start:    $remote_fs
  5. # Required-Stop:
  6. # Default-Start:     S
  7. # Default-Stop:
  8. # X-Interactive:     true
  9. # Description: Set console screen modes and fonts
  10. # Short-Description:    Prepare console
  11. ### END INIT INFO
  12.  
  13. # This is the boot script for the `kbd' package.
  14. # It loads parameters from /etc/kbd/config and maybe loads
  15. # default font and map.
  16. # (c) 1997 Yann Dirson
  17.  
  18. PKG=kbd
  19. if [ -r /etc/$PKG/config ]; then
  20.     . /etc/$PKG/config
  21. fi
  22.  
  23. if [ -d /etc/$PKG/config.d ]; then
  24.     for i in `run-parts --list /etc/$PKG/config.d `; do
  25.        . $i
  26.     done
  27. fi
  28.  
  29. # do some magic with the variables for compatibility with the config
  30. # file of console-tools
  31. for vc in '' `set | grep "^.*_vc[0-9][0-9]*="  | sed 's/^.*\(_vc[0-9][0-9]*\)=.*/\1/'`
  32. do
  33.     eval [ '"'\${SCREEN_FONT$vc}'"' ] && eval CONSOLE_FONT$vc=\${CONSOLE_FONT$vc:-\${SCREEN_FONT$vc}}
  34.     eval [ '"'\${SCREEN_FONT_MAP$vc}'"' ] && eval FONT_MAP$vc=\${FONT_MAP$vc:-\${SCREEN_FONT_MAP$vc}}
  35.     eval [ '"'\${APP_CHARSET_MAP$vc}'"' ] && eval CONSOLE_MAP$vc=\${CONSOLE_MAP$vc:-\${APP_CHARSET_MAP$vc}}
  36. done
  37.  
  38. . /lib/lsb/init-functions
  39.  
  40. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  41. SETFONT_OPT="-v"
  42.  
  43. if which setupcon >/dev/null
  44. then
  45.     HAVE_SETUPCON=yes
  46. fi
  47.  
  48. # set DEVICE_PREFIX depending on devfs/udev
  49. if [ -d /dev/vc ]; then
  50.     DEVICE_PREFIX="/dev/vc/"
  51. else
  52.     DEVICE_PREFIX="/dev/tty"
  53. fi
  54.  
  55. # determine the system charmap
  56. ENV_FILE=''
  57. [ -r /etc/environment ] && ENV_FILE="/etc/environment"
  58. [ -r /etc/default/locale ] && ENV_FILE="/etc/default/locale"
  59. [ "$ENV_FILE" ] && CHARMAP=$(set -a && . "$ENV_FILE" && locale charmap)
  60. if [ "$CHARMAP" = "UTF-8" -a -z "$CONSOLE_MAP" ]
  61. then
  62.     UNICODE_MODE=yes
  63. fi
  64.  
  65. reset_vga_palette ()
  66. {
  67.     if [ -f /proc/fb ]; then
  68.         # They have a framebuffer device.
  69.         # That means we have work to do...
  70.         echo -n "]R"
  71.     fi
  72. }
  73.  
  74. unicode_start_stop ()
  75. {
  76.     vc=$1
  77.     if [ -n "$UNICODE_MODE" -a -z "`eval echo \\$CONSOLE_MAP_vc$vc`" ]; then
  78.         action=unicode_start
  79.     else
  80.         action=unicode_stop
  81.     fi
  82.     if [ "${CONSOLE_FONT}" ]; then
  83.         $action "${CONSOLE_FONT}" < ${DEVICE_PREFIX}$vc > ${DEVICE_PREFIX}$vc 2> /dev/null || true
  84.     else
  85.         $action < ${DEVICE_PREFIX}$vc > ${DEVICE_PREFIX}$vc 2> /dev/null || true
  86.     fi
  87. }
  88.  
  89. setup ()
  90. {
  91.     # be sure the main program is installed
  92.     which setfont >/dev/null || return
  93.  
  94.     VT="no"
  95.     # If we can't access the console, quit
  96.     CONSOLE_TYPE=`fgconsole 2>/dev/null` || return
  97.  
  98.     if [ ! $CONSOLE_TYPE = "serial" ]; then
  99.         readlink /proc/self/fd/0 | grep -q -e /dev/vc -e '/dev/tty[^p]' -e /dev/console
  100.         if [ $? -eq 0 ]; then
  101.             VT="yes"
  102.             reset_vga_palette
  103.         fi
  104.     fi
  105.  
  106.     [ $VT = "no" ] && return
  107.  
  108.     # start vcstime
  109.     if [ "${DO_VCSTIME}" = "yes" ] && which vcstime >/dev/null; then
  110.         [ "$VERBOSE" != "no" ] && log_action_begin_msg "Starting clock on text console"
  111.         vcstime &
  112.         [ "$VERBOSE" != "no" ] && log_action_end_msg 0
  113.     fi
  114.  
  115.     if [ -d /etc/init ] && which initctl >/dev/null; then
  116.         # Upstart
  117.         LIST_CONSOLES=`cd /etc/init; find -name 'tty*.conf' -printf '%f ' | sed -e 's/[^0-9 ]//g'`
  118.     else
  119.         # traditional SysV init
  120.         LIST_CONSOLES=`sed -e '/^ *#/d' /etc/inittab | grep -e '\<tty[0-9]*\>' | awk -F: '{printf "%s ", $1}'`
  121.     fi
  122.  
  123.     # Global default font+map
  124.     if [ -z "${HAVE_SETUPCON}" -a "${CONSOLE_FONT}" ]; then
  125.         [ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up general console font"
  126.         sfm="${FONT_MAP}" && [ "$sfm" ] && sfm="-u $sfm"
  127.         acm="${CONSOLE_MAP}" && [ "$acm" ] && acm="-m $acm"
  128.     
  129.         # Set for the first 6 VCs (as they are allocated in /etc/inittab)
  130.         for vc in $LIST_CONSOLES
  131.         do
  132.             if ! ( unicode_start_stop $vc \
  133.                    && setfont -C ${DEVICE_PREFIX}$vc ${SETFONT_OPT} $sfm ${CONSOLE_FONT} $acm )
  134.             then
  135.                 [ "$VERBOSE" != "no" ] && log_action_end_msg 1
  136.                 break
  137.             fi
  138.         done
  139.         [ "$VERBOSE" != "no" ] && log_action_end_msg 0
  140.     fi
  141.  
  142.     # Default to Unicode mode for new VTs?
  143.     if [ -f /sys/module/vt/parameters/default_utf8 ]; then
  144.         if [ -n "$UNICODE_MODE" ]; then
  145.             echo 1
  146.         else
  147.             echo 0
  148.         fi > /sys/module/vt/parameters/default_utf8
  149.     fi
  150.  
  151.     # Per-VC font+sfm
  152.     PERVC_FONTS="`set | grep "^CONSOLE_FONT_vc[0-9]*="  | tr -d \' `"
  153.     if [ -z "${HAVE_SETUPCON}" -a "${PERVC_FONTS}" ]; then
  154.         [ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up per-VC fonts"
  155.         for font in ${PERVC_FONTS}
  156.         do
  157.             # extract VC and FONTNAME info from variable setting
  158.             vc=`echo $font | cut -b16- | cut -d= -f1`
  159.             eval font=\$CONSOLE_FONT_vc$vc
  160.             # eventually find an associated SFM
  161.             eval sfm=\${FONT_MAP_vc${vc}}
  162.             [ "$sfm" ] && sfm="-u $sfm"
  163.             if ! ( unicode_start_stop $vc \
  164.                    && setfont -C ${DEVICE_PREFIX}$vc ${SETFONT_OPT} $sfm $font )
  165.             then
  166.                 [ "$VERBOSE" != "no" ] && log_action_end_msg 1
  167.                 break
  168.             fi
  169.         done
  170.         [ "$VERBOSE" != "no" ] && log_action_end_msg 0
  171.     fi
  172.  
  173.  
  174.     # Per-VC ACMs
  175.     PERVC_ACMS="`set | grep "^CONSOLE_MAP_vc[0-9]*="  | tr -d \' `"
  176.     if [ -z "${HAVE_SETUPCON}" -a "${PERVC_ACMS}" ]; then
  177.         [ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up per-VC ACM's"
  178.         for acm in ${PERVC_ACMS}
  179.           do
  180.           # extract VC and ACM_FONTNAME info from variable setting
  181.           vc=`echo $acm | cut -b15- | cut -d= -f1`
  182.           eval acm=\$CONSOLE_MAP_vc$vc
  183.           if ! setfont -C "${DEVICE_PREFIX}$vc" ${SETFONT_OPT} -m "$acm"; then
  184.               [ "$VERBOSE" != "no" ] && log_action_end_msg 1
  185.               break
  186.           fi
  187.         done
  188.         [ "$VERBOSE" != "no" ] && log_action_end_msg 0
  189.     fi
  190.     
  191.  
  192.     # screensaver stuff
  193.     setterm_args=""
  194.     if [ "$BLANK_TIME" ]; then
  195.         setterm_args="$setterm_args -blank $BLANK_TIME"
  196.     fi
  197.     if [ "$BLANK_DPMS" ]; then
  198.         setterm_args="$setterm_args -powersave $BLANK_DPMS"
  199.     fi
  200.     if [ "$POWERDOWN_TIME" ]; then
  201.         setterm_args="$setterm_args -powerdown $POWERDOWN_TIME"
  202.     fi
  203.     if [ "$setterm_args" ]; then
  204.         setterm $setterm_args 
  205.     fi
  206.  
  207.     # Keyboard rate and delay
  208.     KBDRATE_ARGS=""
  209.     if [ -n "$KEYBOARD_RATE" ]; then
  210.         KBDRATE_ARGS="-r $KEYBOARD_RATE"
  211.     fi
  212.     if [ -n "$KEYBOARD_DELAY" ]; then
  213.         KBDRATE_ARGS="$KBDRATE_ARGS -d $KEYBOARD_DELAY"
  214.     fi
  215.     if [ -n "$KBDRATE_ARGS" ]; then
  216.         [ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting keyboard rate and delay"
  217.         kbdrate -s $KBDRATE_ARGS
  218.         [ "$VERBOSE" != "no" ] && log_action_end_msg 0
  219.     fi
  220.  
  221.     # Inform gpm if present, of potential changes.
  222.     if [ -f /var/run/gpm.pid ]; then
  223.         kill -s WINCH `cat /var/run/gpm.pid` 2> /dev/null
  224.     fi
  225.  
  226.     # Allow user to remap keys on the console
  227.     if [ -z "${HAVE_SETUPCON}" -a -r /etc/$PKG/remap ]; then
  228.         dumpkeys < ${DEVICE_PREFIX}1 | sed -f /etc/$PKG/remap | loadkeys --quiet
  229.     fi
  230.  
  231.     # Set LEDS here
  232.     if [ -n "$LEDS" ]; then
  233.         for i in $LIST_CONSOLES
  234.         do
  235.             setleds -D $LEDS < $DEVICE_PREFIX$i
  236.         done
  237.     fi
  238. }
  239.  
  240. case "$1" in
  241.     start|reload|restart|force-reload)
  242.         if [ -n "$HAVE_SETUPCON" ]
  243.         then
  244.                 log_action_msg "Setting console screen modes"
  245.         else
  246.                 log_action_msg "Setting console screen modes and fonts"
  247.         fi
  248.         setup
  249.     [ -z "$HAVE_SETUPCON" ] || log_action_msg "Skipping font and keymap setup (handled by console-setup)"
  250.         ;;
  251.     stop)
  252.         ;;
  253.     *)
  254.         setup
  255.         ;;
  256. esac
  257.  
  258. :
  259.  
  260.